package com;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

@ContextConfiguration(locations = { "file:webroot/WEB-INF/conf/spring/auto-proxy-beans.xml",
                                    "file:webroot/WEB-INF/conf/spring/data-source-beans.xml",
//                                    "file:webroot/WEB-INF/conf/spring/sms-beans.xml",
                                   "file:webroot/WEB-INF/conf/spring/service-beans.xml",
                                   "file:webroot/WEB-INF/conf/spring/mail-beans.xml"
                               //    "file:testsrc/web-beans-test.xml"
                                   }
)
public class BizTestBase extends AbstractTransactionalJUnit4SpringContextTests {

    private static final String WebRootDir = "webroot";

    public BizTestBase() {
        super();
        setClassPath();
    }

    public static void setClassPath() {
        ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
        URL thisClass = currentLoader.getResource("log4j.properties");
        File thisClassFile = new File(thisClass.getFile());
        File rootDir = thisClassFile.getParentFile().getParentFile();
        File webrootDir = new File(rootDir, WebRootDir);
        try {
            ClassLoader cl = new URLClassLoader(new URL[] { webrootDir.toURI().toURL() },
                currentLoader);
            Thread.currentThread().setContextClassLoader(cl);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
